// pages/mycase/mycase.js
import { ajax, src, util } from "../../utils/util.js";
const app = getApp();

let isIphoneX = app.globalData.isIphoneX;

Page({

  /**
   * 页面的初始数据
   */
  data: {
    uqid:'',
    navH: app.globalData.navHeight,
    currentTab:4,
    myreserve:''
  },
 

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var uqid = wx.getStorageSync("uqid");
    this.setData({
      uqid: uqid
    });
    
  },

  clickTab:function(e){
    var currentTab = e.currentTarget.dataset.current;
    this.setData({
      currentTab: currentTab
    })
    this.getlist()
  },
  getlist:function(){
    ajax("/api/index/order_list", {
      data: {
        uqid: this.data.uqid,
        pay_status: this.data.currentTab == 4 ? '' : this.data.currentTab,
        page:1,
        limit:40,
      },
      header: {
        'Accept': 'application/json', // 默认值
      },
    }, res => {
      console.log(res);
      if (res.error == 0) {
        this.setData({
          myreserve:res.data
        })
        
      }
    })
  },


  gotopay:function(e){
    var index = e.currentTarget.dataset.index;
    var info = this.data.myreserve.data[index].sin_data
    
    wx.requestPayment({
      timeStamp: info.timeStamp,
      nonceStr: info.nonceStr,
      package: info.package,
      signType: info.signType,
      paySign: info.paySign,
      success(res) {
        console.log(res)

        wx.redirectTo({
          url: '/pages/paysuccess/paysuccess',
        })
       
      },
      fail(res) {
        console.log('支付失败')
      }
    })
  },
 

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var uqid = wx.getStorageSync("uqid");
    this.setData({
      uqid: uqid
    });
    this.getlist()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  
})